package com.khotyn.heresy.service;

import com.khotyn.heresy.bean.Album;
import com.khotyn.heresy.bean.PictureAlbum;
import com.khotyn.heresy.dao.AlbumDAO;
import com.khotyn.heresy.dao.PictureAlbumDAO;
import com.khotyn.heresy.dao.PictureDAO;

/**
 * 复制图片服务类
 * 
 * @author 黄挺
 * 
 */
public class CopyPictureService {
	private PictureAlbumDAO pictureAlbumDAO;
	private AlbumDAO albumDAO;
	private PictureDAO pictureDAO;

	/**
	 * 复制图片服务类
	 * 
	 * @param albumID 相册ID
	 * @param pictureID 图片ID
	 * @param userID 用户ID
	 * @param requestURL 请求URL
	 */
	public void doService(Integer albumID, String pictureID, Integer userID, String requestURL) {
		PictureAlbum pictureAlbum = new PictureAlbum();

		pictureAlbum.setAlbumID(albumID);
		pictureAlbum.getPictureBrief().setPictureID(pictureID);

		doDBOperate(pictureAlbum);
	}

	/**
	 * 复制图片服务函数
	 * 
	 * @param browseLog 日志Bean
	 * @param pictureAlbum 图片相册关联Bean
	 */
	public void doDBOperate(PictureAlbum pictureAlbum) {

		pictureAlbumDAO.insertPictureAlbum(pictureAlbum);
		Album album = albumDAO.selectAlbumByID(pictureAlbum.getAlbumID());

		if (album.getPictureCount() == 0) {
			String thumbLocation = pictureDAO.selectPicBriefByPicId(pictureAlbum.getPictureBrief().getPictureID()).getThumbLocation();
			albumDAO.updateEnvelopPicId(album.getAlbumID(), thumbLocation);
		}
		album.setPictureCount(album.getPictureCount() + 1);
		albumDAO.updatePictureCount(album);
	}

	public void setPictureAlbumDAO(PictureAlbumDAO pictureAlbumDAO) {
		this.pictureAlbumDAO = pictureAlbumDAO;
	}

	public void setAlbumDAO(AlbumDAO albumDAO) {
		this.albumDAO = albumDAO;
	}

	public AlbumDAO getAlbumDAO() {
		return albumDAO;
	}

	public void setPictureDAO(PictureDAO pictureDAO) {
		this.pictureDAO = pictureDAO;
	}
}
